package com.lyshop.jinding.core;

import android.content.Context;
import android.os.Handler;

import com.lyshop.jinding.bean.AddressBean;
import com.lyshop.jinding.bean.BankListBean;
import com.lyshop.jinding.bean.BindCardBean;
import com.lyshop.jinding.bean.CalendarBean;
import com.lyshop.jinding.bean.CalendarDetail;
import com.lyshop.jinding.bean.CreateOrderResultBean;
import com.lyshop.jinding.bean.CreateShopProductBean;
import com.lyshop.jinding.bean.CredentialBean;
import com.lyshop.jinding.bean.EXPRecordBean;
import com.lyshop.jinding.bean.FollowGreatPeopleInfo;
import com.lyshop.jinding.bean.FollowListBean;
import com.lyshop.jinding.bean.FollowOrderBean;
import com.lyshop.jinding.bean.FollowUserBean;
import com.lyshop.jinding.bean.FreshListBean;
import com.lyshop.jinding.bean.GifBean;
import com.lyshop.jinding.bean.GoodsTicketInfoBean;
import com.lyshop.jinding.bean.HeaderSelectBean;
import com.lyshop.jinding.bean.HomeData;
import com.lyshop.jinding.bean.ImageItemBean;
import com.lyshop.jinding.bean.ImportDialogBean;
import com.lyshop.jinding.bean.ImportantBean;
import com.lyshop.jinding.bean.IntegralRecordBean;
import com.lyshop.jinding.bean.IntegralTicketBean;
import com.lyshop.jinding.bean.InvestSchoolGroupBean;
import com.lyshop.jinding.bean.NewsNoticeBean;
import com.lyshop.jinding.bean.OrderInfoBean;
import com.lyshop.jinding.bean.RechargeBean;
import com.lyshop.jinding.bean.RechargeSettingBean;
import com.lyshop.jinding.bean.RedBagBean;
import com.lyshop.jinding.bean.RetailOrderBean;
import com.lyshop.jinding.bean.RetailTicketBean;
import com.lyshop.jinding.bean.SellOrderInfoBean;
import com.lyshop.jinding.bean.ShopGoodsListBean;
import com.lyshop.jinding.bean.SignBean;
import com.lyshop.jinding.bean.TakeMoneyTipsBean;
import com.lyshop.jinding.bean.TicketBean;
import com.lyshop.jinding.bean.TransfeRecordBean;
import com.lyshop.jinding.bean.TurnCardBean;
import com.lyshop.jinding.bean.TxLiveTokenBean;
import com.lyshop.jinding.bean.UserBalanceBean;
import com.lyshop.jinding.bean.UserBankCardBean;
import com.lyshop.jinding.bean.UserIdCardBean;
import com.lyshop.jinding.bean.UserInfoBean;
import com.lyshop.jinding.bean.UserMessageBean;
import com.lyshop.jinding.bean.VersionBean;
import com.lyshop.jinding.bean.WelfareTaskBean;
import com.lyshop.jinding.constants.Constant;
import com.lyshop.jinding.net.ActionCallbackListener;
import com.lyshop.jinding.net.Api;
import com.lyshop.jinding.net.ApiCallBack;
import com.lyshop.jinding.net.ApiImpl;
import com.lyshop.jinding.net.ApiResponse;
import com.lyshop.jinding.utils.LogUtil;
import com.zc.mychart.model.GoodsAllBean;

import java.util.List;

public class AppActionImpl implements AppAction {
    private Context mContext;
    private Api api;
    private Handler mHandler = new Handler();

    public AppActionImpl(Context context) {
        this.mContext = context;
        this.api = new ApiImpl(context);
    }

    /**
     * 首页公告
     *
     * @param listener
     */
    @Override
    public void getNewNoticeList(final ActionCallbackListener<List<NewsNoticeBean>> listener) {
        api.getNewNoticeList(new ApiCallBack<ApiResponse<List<NewsNoticeBean>>>() {
            @Override
            public void onSuccess(ApiResponse<List<NewsNoticeBean>> data) {
                successHandler(data, listener);
            }

            @Override
            public void onFailure(String errorCode, String message) {
                failedHandler(listener, errorCode, message);
            }
        });
    }

    /**
     * 重要数据
     *
     * @param listener
     */
    @Override
    public void getImportant(ActionCallbackListener<ImportantBean> listener) {
        api.getImportant(new ApiCallBack<ApiResponse<ImportantBean>>() {
            @Override
            public void onSuccess(ApiResponse<ImportantBean> data) {
                successHandler(data, listener);
            }

            @Override
            public void onFailure(String errorCode, String message) {
                failedHandler(listener, errorCode, message);
            }
        });
    }

    /**
     * 牛单广场
     *
     * @param listener
     */
    @Override
    public void getOrderSquare(ActionCallbackListener<List<SellOrderInfoBean>> listener) {
        api.getOrderSquare(new ApiCallBack<ApiResponse<List<SellOrderInfoBean>>>() {
            @Override
            public void onSuccess(ApiResponse<List<SellOrderInfoBean>> data) {
                successHandler(data, listener);
            }

            @Override
            public void onFailure(String errorCode, String message) {

            }
        });
    }

    /**
     * 商城列表
     *
     * @param page
     * @param listener
     */
    @Override
    public void getRetailGoods(int page, ActionCallbackListener<List<ShopGoodsListBean>> listener) {
        api.getRetailGoods(page, new ApiCallBack<ApiResponse<List<ShopGoodsListBean>>>() {
            @Override
            public void onSuccess(ApiResponse<List<ShopGoodsListBean>> data) {
                successHandler(data, listener);
            }

            @Override
            public void onFailure(String errorCode, String message) {
                failedHandler(listener, errorCode, message);
            }
        });
    }

    /**
     * 获取腾讯人脸核验sdk配置
     *
     * @param listener
     */
    @Override
    public void getTxLiveSdk(String cert_no, String user_name, ActionCallbackListener<TxLiveTokenBean> listener) {
        api.getTxLiveSdk(cert_no, user_name, new ApiCallBack<ApiResponse<TxLiveTokenBean>>() {
            @Override
            public void onSuccess(ApiResponse<TxLiveTokenBean> data) {
                successHandler(data, listener);
            }

            @Override
            public void onFailure(String errorCode, String message) {
                failedHandler(listener, errorCode, message);
            }
        });
    }

    /**
     * 获取腾讯云sdk配置
     *
     * @param listener
     */
    @Override
    public void getCosUpload(ActionCallbackListener<CredentialBean> listener) {
        api.getCosUpload(new ApiCallBack<ApiResponse<CredentialBean>>() {
            @Override
            public void onSuccess(ApiResponse<CredentialBean> data) {
                successHandler(data, listener);
            }

            @Override
            public void onFailure(String errorCode, String message) {
                failedHandler(listener, errorCode, message);
            }
        });
    }

    /**
     * 获取支持银行列表
     *
     * @param tcId
     * @param listener
     */
    @Override
    public void getBankList(String tcId, ActionCallbackListener<List<BankListBean>> listener) {
        api.getBankList(tcId, new ApiCallBack<ApiResponse<List<BankListBean>>>() {
            @Override
            public void onSuccess(ApiResponse<List<BankListBean>> data) {
                successHandler(data, listener);
            }

            @Override
            public void onFailure(String errorCode, String message) {
                failedHandler(listener, errorCode, message);
            }
        });
    }

    /**
     * 跟单广场
     *
     * @param openTime 时间排序
     * @param contract 商品
     * @param follow   关注
     * @param level    等级
     * @param listener
     */
    @Override
    public void getFollowList(int page, boolean openTime, String contract, boolean follow, String level, ActionCallbackListener<List<FollowOrderBean>> listener) {
        api.getFollowList(page, openTime, contract, follow, level, new ApiCallBack<ApiResponse<List<FollowOrderBean>>>() {
            @Override
            public void onSuccess(ApiResponse<List<FollowOrderBean>> data) {
                successHandler(data, listener);
            }

            @Override
            public void onFailure(String errorCode, String message) {
                failedHandler(listener, errorCode, message);
            }
        });
    }

    @Override
    public void getGifList(ActionCallbackListener<List<GifBean>> listener) {
        api.getGifList(new ApiCallBack<ApiResponse<List<GifBean>>>() {
            @Override
            public void onSuccess(ApiResponse<List<GifBean>> data) {
                successHandler(data, listener);
            }

            @Override
            public void onFailure(String errorCode, String message) {
                failedHandler(listener, errorCode, message);
            }
        });
    }


    /**
     * 获取k线图数据
     *
     * @param pro_code
     * @param type
     * @param listener
     */
    @Override
    public void getKMap(String pro_code, String type, ActionCallbackListener<List<List<Double>>> listener) {
        api.getKMap(pro_code, type, new ApiCallBack<ApiResponse<List<List<Double>>>>() {
            @Override
            public void onSuccess(ApiResponse<List<List<Double>>> data) {
                successHandler(data, listener);
            }

            @Override
            public void onFailure(String errorCode, String message) {
                failedHandler(listener, errorCode, message);
            }
        });
    }

    /**
     * 获取支付方式
     *
     * @param listener
     */
    @Override
    public void getPayList(ActionCallbackListener<RechargeSettingBean> listener) {
        api.getPayList(new ApiCallBack<ApiResponse<RechargeSettingBean>>() {
            @Override
            public void onSuccess(ApiResponse<RechargeSettingBean> data) {
                successHandler(data, listener);
            }

            @Override
            public void onFailure(String errorCode, String message) {
                failedHandler(listener, errorCode, message);
            }
        });
    }

    @Override
    public void getCardList(String channel_id, ActionCallbackListener<UserBankCardBean> listener) {
        api.getCardList(channel_id, new ApiCallBack<ApiResponse<UserBankCardBean>>() {
            @Override
            public void onSuccess(ApiResponse<UserBankCardBean> data) {
                if (data != null && data.getData() != null) {
                    successHandler(data, listener);
                } else {
                    successNullHandler(listener);
                }
            }

            @Override
            public void onFailure(String errorCode, String message) {
                failedHandler(listener, errorCode, message);
            }
        });
    }

    /**
     * 支付宝去充值
     *
     * @param listener
     */
    @Override
    public void userSaving(int code, int amount, ActionCallbackListener<RechargeBean> listener) {
        api.userSaving(code, amount, new ApiCallBack<ApiResponse<RechargeBean>>() {
            @Override
            public void onSuccess(ApiResponse<RechargeBean> data) {
                successHandler(data, listener);
            }

            @Override
            public void onFailure(String errorCode, String message) {
                failedHandler(listener, errorCode, message);
            }
        });
    }

    @Override
    public void userSaving(String code, String amount, String card_no, String phone, String card_user_name, String cert_no, String bank, ActionCallbackListener<RechargeBean> listener) {
        api.userSaving(code, amount, card_no, phone, card_user_name, cert_no, bank, new ApiCallBack<ApiResponse<RechargeBean>>() {
            @Override
            public void onSuccess(ApiResponse<RechargeBean> data) {
                successHandler(data, listener);
            }

            @Override
            public void onFailure(String errorCode, String message) {
                failedHandler(listener, errorCode, message);
            }
        });
    }

    /**
     * 上传身份证
     *
     * @param back
     * @param front
     * @param listener
     */
    @Override
    public void uploadCert(String back, String front, ActionCallbackListener<UserIdCardBean> listener) {
        api.uploadCert(back, front, new ApiCallBack<ApiResponse<UserIdCardBean>>() {
            @Override
            public void onSuccess(ApiResponse<UserIdCardBean> data) {
                successHandler(data, listener);
            }

            @Override
            public void onFailure(String errorCode, String message) {
                failedHandler(listener, errorCode, message);
            }
        });
    }

    /**
     * 确认身份信息
     *
     * @param name
     * @param request_id
     * @param listener
     */
    @Override
    public void uploadCertConfirm(String name, String request_id, ActionCallbackListener<Void> listener) {
        api.uploadCertConfirm(name, request_id, new ApiCallBack<ApiResponse<Void>>() {
            @Override
            public void onSuccess(ApiResponse<Void> data) {
                successNullHandler(listener);
            }

            @Override
            public void onFailure(String errorCode, String message) {
                failedHandler(listener, errorCode, message);
            }
        });
    }

    @Override
    public void createPro(OrderInfoBean order, ActionCallbackListener<CreateOrderResultBean> listener) {
        api.createPro(order, new ApiCallBack<ApiResponse<CreateOrderResultBean>>() {
            @Override
            public void onSuccess(ApiResponse<CreateOrderResultBean> data) {
                successHandler(data, listener);
            }

            @Override
            public void onFailure(String errorCode, String message) {
                failedHandler(listener, errorCode, message);
            }
        });
    }

    @Override
    public void getHoldOrderList(ActionCallbackListener<List<OrderInfoBean>> listener) {
        api.getHoldOrderList(new ApiCallBack<ApiResponse<List<OrderInfoBean>>>() {
            @Override
            public void onSuccess(ApiResponse<List<OrderInfoBean>> data) {
                successHandler(data, listener);
            }

            @Override
            public void onFailure(String errorCode, String message) {
                failedHandler(listener, errorCode, message);
            }
        });
    }

    @Override
    public void getHistoryOrderList(int page, ActionCallbackListener<List<OrderInfoBean>> listener) {
        api.getHistoryOrderList(page, new ApiCallBack<ApiResponse<List<OrderInfoBean>>>() {
            @Override
            public void onSuccess(ApiResponse<List<OrderInfoBean>> data) {
                successHandler(data, listener);
            }

            @Override
            public void onFailure(String errorCode, String message) {
                failedHandler(listener, errorCode, message);
            }
        });
    }

    /**
     * 退订
     *
     * @param order_id
     * @param listener
     */
    @Override
    public void sellOrder(String order_id, ActionCallbackListener<Void> listener) {
        api.sellOrder(order_id, new ApiCallBack<ApiResponse<Void>>() {
            @Override
            public void onSuccess(ApiResponse<Void> data) {
                successNullHandler(listener);
            }

            @Override
            public void onFailure(String errorCode, String message) {
                failedHandler(listener, errorCode, message);
            }
        });
    }

    /**
     * 修改订单
     *
     * @param order_id
     * @param target_profit
     * @param stop_loss
     * @param listener
     */
    @Override
    public void editOrderInfo(String order_id, int target_profit, int stop_loss, ActionCallbackListener<Void> listener) {
        api.editOrderInfo(order_id, target_profit, stop_loss, new ApiCallBack<ApiResponse<Void>>() {
            @Override
            public void onSuccess(ApiResponse<Void> data) {
                successNullHandler(listener);
            }

            @Override
            public void onFailure(String errorCode, String message) {
                failedHandler(listener, errorCode, message);
            }
        });
    }

    /**
     * 新手指南
     *
     * @param listener
     */
    @Override
    public void getInvestSchoolList(ActionCallbackListener<List<InvestSchoolGroupBean>> listener) {
        api.getInvestSchoolList(new ApiCallBack<ApiResponse<List<InvestSchoolGroupBean>>>() {
            @Override
            public void onSuccess(ApiResponse<List<InvestSchoolGroupBean>> data) {
                successHandler(data, listener);
            }

            @Override
            public void onFailure(String errorCode, String message) {
                failedHandler(listener, errorCode, message);
            }
        });
    }

    @Override
    public void getRetailTicket(String goods_id, int sceneType, ActionCallbackListener<GoodsTicketInfoBean> listener) {
        api.getRetailTicket(goods_id, sceneType, new ApiCallBack<ApiResponse<GoodsTicketInfoBean>>() {
            @Override
            public void onSuccess(ApiResponse<GoodsTicketInfoBean> data) {
                successHandler(data, listener);
            }

            @Override
            public void onFailure(String errorCode, String message) {
                failedHandler(listener, errorCode, message);
            }
        });
    }

    /**
     * 获取banner
     *
     * @param type
     * @param listener
     */
    @Override
    public void getBanner(String type, ActionCallbackListener<List<ImageItemBean>> listener) {
        api.getBanner(type, new ApiCallBack<ApiResponse<List<ImageItemBean>>>() {
            @Override
            public void onSuccess(ApiResponse<List<ImageItemBean>> data) {
                successHandler(data, listener);
            }

            @Override
            public void onFailure(String errorCode, String message) {
                failedHandler(listener, errorCode, message);
            }
        });
    }

    /**
     * 获取验证码
     *
     * @param mobile   手机号
     * @param listener
     */
    @Override
    public void getRegisterCode(String mobile, ActionCallbackListener<Void> listener) {
        if (mobile == null || mobile.isEmpty() || mobile.length() != 11) {
            failedHandler(listener, Constant.FAILED, "请输入正确的手机号");
        } else {
            api.getRegisterCode(mobile, new ApiCallBack<ApiResponse<Void>>() {
                @Override
                public void onSuccess(ApiResponse<Void> data) {
                    successNullHandler(listener);
                }

                @Override
                public void onFailure(String errorCode, String message) {
                    failedHandler(listener, errorCode, message);
                }
            });
        }
    }

    /**
     * 注册
     *
     * @param mobile         手机号
     * @param code           验证码
     * @param trade_password 密码
     * @param pushId
     * @param listener
     */
    @Override
    public void register(String mobile, String code, String trade_password, String pushId, final ActionCallbackListener<Void> listener) {
        if (mobile == null || mobile.isEmpty() || mobile.length() != 11) {
            failedHandler(listener, Constant.FAILED, "请输入正确的手机号");
        } else if (code == null || code.isEmpty()) {
            failedHandler(listener, Constant.FAILED, "请输入验证码");
        } else if (trade_password == null || trade_password.length() < 6) {
            failedHandler(listener, Constant.FAILED, "请输入6位以上密码");
        } else {
            api.register(mobile, code, trade_password, pushId, new ApiCallBack<ApiResponse<Void>>() {
                @Override
                public void onSuccess(ApiResponse<Void> data) {
                    successNullHandler(listener);
                }

                @Override
                public void onFailure(String errorCode, String message) {
                    failedHandler(listener, errorCode, message);
                }
            });
        }
    }

    /**
     * 登录
     *
     * @param mobile   手机号
     * @param password 密码
     * @param pushId   推送id
     * @param listener
     */
    @Override
    public void login(String mobile, String password, String pushId, final ActionCallbackListener<UserInfoBean> listener) {
        if (mobile == null || mobile.isEmpty() || mobile.length() != 11) {
            failedHandler(listener, Constant.FAILED, "请输入正确的手机号");
        } else if (password == null || password.length() < 6) {
            failedHandler(listener, Constant.FAILED, "请输入6位以上密码");
        } else {
            api.login(mobile, password, pushId, new ApiCallBack<ApiResponse<UserInfoBean>>() {
                @Override
                public void onSuccess(ApiResponse<UserInfoBean> data) {
                    successHandler(data, listener);
                }

                @Override
                public void onFailure(String errorCode, String message) {
                    failedHandler(listener, errorCode, message);
                }
            });
        }
    }

    /**
     * 一键登录
     *
     * @param token
     * @param listener
     */
    @Override
    public void authOneKey(String token, String pushId, final ActionCallbackListener<UserInfoBean> listener) {
        api.authOneKey(token, pushId, new ApiCallBack<ApiResponse<UserInfoBean>>() {
            @Override
            public void onSuccess(ApiResponse<UserInfoBean> data) {
                successHandler(data, listener);
            }

            @Override
            public void onFailure(String errorCode, String message) {
                failedHandler(listener, errorCode, message);
            }
        });
    }

    /**
     * 获取用户信息
     *
     * @param listener
     */
    @Override
    public void getUserDetail(ActionCallbackListener<UserInfoBean> listener) {
        api.getUserDetail(new ApiCallBack<ApiResponse<UserInfoBean>>() {
            @Override
            public void onSuccess(ApiResponse<UserInfoBean> data) {
                successHandler(data, listener);
            }

            @Override
            public void onFailure(String errorCode, String message) {
                failedHandler(listener, errorCode, message);
            }
        });
    }

    /**
     * 忘记密码获取验证码
     *
     * @param mobile
     * @param listener
     */
    @Override
    public void resetPasswordCode(String mobile, final ActionCallbackListener<Void> listener) {
        if (mobile == null || mobile.isEmpty() || mobile.length() != 11) {
            failedHandler(listener, Constant.FAILED, "请输入正确的手机号");
        } else {
            api.resetPasswordCode(mobile, 0, new ApiCallBack<ApiResponse<Void>>() {
                @Override
                public void onSuccess(ApiResponse<Void> data) {
                    successNullHandler(listener);
                }

                @Override
                public void onFailure(String errorCode, String message) {
                    failedHandler(listener, errorCode, message);
                }
            });
        }
    }

    /**
     * 重置忘记密码
     *
     * @param mobile
     * @param code
     * @param password
     * @param listener
     */
    @Override
    public void resetPassword(String mobile, String code, String password, final ActionCallbackListener<Void> listener) {
        if (mobile == null || mobile.isEmpty() || mobile.length() != 11) {
            failedHandler(listener, Constant.FAILED, "请输入正确的手机号");
        } else if (code == null || code.isEmpty()) {
            failedHandler(listener, Constant.FAILED, "请输入验证码");
        } else if (password == null || password.isEmpty()) {
            failedHandler(listener, Constant.FAILED, "请输入新密码");
        } else {
            api.resetPassword(mobile, code, password, new ApiCallBack<ApiResponse<Void>>() {
                @Override
                public void onSuccess(ApiResponse<Void> data) {
                    successNullHandler(listener);
                }

                @Override
                public void onFailure(String errorCode, String message) {
                    failedHandler(listener, errorCode, message);
                }
            });
        }
    }

    /**
     * 获取所有合约
     *
     * @param listener
     */
    @Override
    public void getAllList(final ActionCallbackListener<List<GoodsAllBean>> listener) {
        api.getAllList(new ApiCallBack<ApiResponse<List<GoodsAllBean>>>() {
            @Override
            public void onSuccess(final ApiResponse<List<GoodsAllBean>> data) {
                successHandler(data, listener);
            }

            @Override
            public void onFailure(String errorCode, String message) {
                failedHandler(listener, errorCode, message);
            }
        });
    }

    @Override
    public void getWelfareList(ActionCallbackListener<WelfareTaskBean> listener) {

        api.getWelfareList(new ApiCallBack<ApiResponse<WelfareTaskBean>>() {
            @Override
            public void onSuccess(ApiResponse<WelfareTaskBean> data) {
                successHandler(data, listener);
            }

            @Override
            public void onFailure(String errorCode, String message) {
                failedHandler(listener, errorCode, message);
            }
        });
    }

    @Override
    public void signPost(ActionCallbackListener<Void> listener) {
        api.signPost(new ApiCallBack<ApiResponse<Void>>() {
            @Override
            public void onSuccess(ApiResponse<Void> data) {
                successNullHandler(listener);
            }

            @Override
            public void onFailure(String errorCode, String message) {
                failedHandler(listener, errorCode, message);
            }
        });
    }

    @Override
    public void getTaskszIntegral(String list_id, String tasks_id, ActionCallbackListener<Void> listener) {
        api.getTaskszIntegral(list_id, tasks_id, new ApiCallBack<ApiResponse<Void>>() {
            @Override
            public void onSuccess(ApiResponse<Void> data) {
                successNullHandler(listener);
            }

            @Override
            public void onFailure(String errorCode, String message) {
                failedHandler(listener, errorCode, message);
            }
        });
    }

    @Override
    public void takeMoneyGetCode(ActionCallbackListener<Void> listener) {
        api.takeMoneyGetCode(new ApiCallBack<ApiResponse<Void>>() {
            @Override
            public void onSuccess(ApiResponse<Void> data) {
                successNullHandler(listener);
            }

            @Override
            public void onFailure(String errorCode, String message) {
                failedHandler(listener, errorCode, message);
            }
        });
    }

    @Override
    public void takeMoneySubmit(String amount, String channel_id, String sms_code, ActionCallbackListener<Void> listener) {
        api.takeMoneySubmit(amount, channel_id, sms_code, new ApiCallBack<ApiResponse<Void>>() {
            @Override
            public void onSuccess(ApiResponse<Void> data) {
                successNullHandler(listener);
            }

            @Override
            public void onFailure(String errorCode, String message) {
                failedHandler(listener, errorCode, message);
            }
        });
    }

    @Override
    public void takeMoneyTips(ActionCallbackListener<TakeMoneyTipsBean> listener) {
        api.takeMoneyTips(new ApiCallBack<ApiResponse<TakeMoneyTipsBean>>() {
            @Override
            public void onSuccess(ApiResponse<TakeMoneyTipsBean> data) {
                successHandler(data, listener);
            }

            @Override
            public void onFailure(String errorCode, String message) {
                failedHandler(listener, errorCode, message);
            }
        });
    }

    @Override
    public void unbindCard(String channel_id, String code, ActionCallbackListener<Void> listener) {
        api.unbindCard(channel_id, code, new ApiCallBack<ApiResponse<Void>>() {
            @Override
            public void onSuccess(ApiResponse<Void> data) {
                successNullHandler(listener);
            }

            @Override
            public void onFailure(String errorCode, String message) {
                failedHandler(listener, errorCode, message);
            }
        });
    }

    @Override
    public void getIntegralTicketListData(ActionCallbackListener<List<IntegralTicketBean>> listener) {
        api.getIntegralTicketListData(new ApiCallBack<ApiResponse<List<IntegralTicketBean>>>() {
            @Override
            public void onSuccess(ApiResponse<List<IntegralTicketBean>> data) {
                successHandler(data, listener);
            }

            @Override
            public void onFailure(String errorCode, String message) {
                failedHandler(listener, errorCode, message);
            }
        });
    }

    @Override
    public void userRechargeConfirm(String bind_card_id, String order_no, String code, ActionCallbackListener<Void> listener) {
        api.userRechargeConfirm(bind_card_id, order_no, code, new ApiCallBack<ApiResponse<Void>>() {
            @Override
            public void onSuccess(ApiResponse<Void> data) {
                successNullHandler(listener);
            }

            @Override
            public void onFailure(String errorCode, String message) {
                failedHandler(listener, errorCode, message);
            }
        });
    }

    @Override
    public void exchangeTicket(String list_id, ActionCallbackListener<Void> listener) {
        api.exchangeTicket(list_id, new ApiCallBack<ApiResponse<Void>>() {
            @Override
            public void onSuccess(ApiResponse<Void> data) {
                successNullHandler(listener);
            }

            @Override
            public void onFailure(String errorCode, String message) {
                failedHandler(listener, errorCode, message);
            }
        });
    }

    @Override
    public void getSignDataList(ActionCallbackListener<List<SignBean>> listener) {
        api.getSignDataList(new ApiCallBack<ApiResponse<List<SignBean>>>() {
            @Override
            public void onSuccess(ApiResponse<List<SignBean>> data) {
                successHandler(data, listener);
            }

            @Override
            public void onFailure(String errorCode, String message) {
                failedHandler(listener, errorCode, message);
            }
        });
    }

    @Override
    public void getUnbindCardCode(ActionCallbackListener<Void> listener) {
        api.getUnbindCardCode(new ApiCallBack<ApiResponse<Void>>() {
            @Override
            public void onSuccess(ApiResponse<Void> data) {
                successNullHandler(listener);
            }

            @Override
            public void onFailure(String errorCode, String message) {
                failedHandler(listener, errorCode, message);
            }
        });
    }

    /**
     * 获取地址列表
     *
     * @param listener
     */
    @Override
    public void getAddressList(ActionCallbackListener<List<AddressBean>> listener) {
        api.getAddressList(new ApiCallBack<ApiResponse<List<AddressBean>>>() {
            @Override
            public void onSuccess(ApiResponse<List<AddressBean>> data) {
                successHandler(data, listener);
            }

            @Override
            public void onFailure(String errorCode, String message) {
                failedHandler(listener, errorCode, message);
            }
        });
    }

    /**
     * 零售商品下单
     *
     * @param bean
     * @param listener
     */
    @Override
    public void createShopOrder(CreateShopProductBean bean, ActionCallbackListener<Void> listener) {
        api.createShopOrder(bean, new ApiCallBack<ApiResponse<Void>>() {
            @Override
            public void onSuccess(ApiResponse<Void> data) {
                successNullHandler(listener);
            }

            @Override
            public void onFailure(String errorCode, String message) {
                failedHandler(listener, errorCode, message);
            }
        });
    }

    /**
     * 删除地址
     *
     * @param id
     * @param listener
     */
    @Override
    public void deleteAddress(String id, ActionCallbackListener<Void> listener) {
        api.deleteAddress(id, new ApiCallBack<ApiResponse<Void>>() {
            @Override
            public void onSuccess(ApiResponse<Void> data) {
                successNullHandler(listener);
            }

            @Override
            public void onFailure(String errorCode, String message) {
                failedHandler(listener, errorCode, message);
            }
        });
    }

    /**
     * 创建地址
     *
     * @param mAddressBean
     * @param listener
     */
    @Override
    public void createAddress(AddressBean mAddressBean, ActionCallbackListener<Void> listener) {
        api.createAddress(mAddressBean, new ApiCallBack<ApiResponse<Void>>() {
            @Override
            public void onSuccess(ApiResponse<Void> data) {
                successNullHandler(listener);
            }

            @Override
            public void onFailure(String errorCode, String message) {
                failedHandler(listener, errorCode, message);
            }
        });
    }

    /**
     * 编辑地址
     *
     * @param mAddressBean
     * @param listener
     */
    @Override
    public void editAddress(AddressBean mAddressBean, ActionCallbackListener<Void> listener) {
        api.editAddress(mAddressBean, new ApiCallBack<ApiResponse<Void>>() {
            @Override
            public void onSuccess(ApiResponse<Void> data) {
                successNullHandler(listener);
            }

            @Override
            public void onFailure(String errorCode, String message) {
                failedHandler(listener, errorCode, message);
            }
        });
    }

    /**
     * 提货
     *
     * @param bean
     * @param listener
     */
    @Override
    public void createProduct(CreateShopProductBean bean, ActionCallbackListener<Void> listener) {
        api.createProduct(bean, new ApiCallBack<ApiResponse<Void>>() {
            @Override
            public void onSuccess(ApiResponse<Void> data) {
                successNullHandler(listener);
            }

            @Override
            public void onFailure(String errorCode, String message) {
                failedHandler(listener, errorCode, message);
            }
        });
    }

    /**
     * 绑定银行卡
     *
     * @param channel_id
     * @param card_no
     * @param phone
     * @param cert_no
     * @param bank_code
     * @param card_user_name
     * @param listener
     */
    @Override
    public void bindCard(String channel_id, String card_no, String phone, String cert_no, String bank_code, String card_user_name, ActionCallbackListener<BindCardBean> listener) {
        api.bindCard(channel_id, card_no, phone, cert_no, bank_code, card_user_name, new ApiCallBack<ApiResponse<BindCardBean>>() {
            @Override
            public void onSuccess(ApiResponse<BindCardBean> data) {
                successHandler(data, listener);
            }

            @Override
            public void onFailure(String errorCode, String message) {
                failedHandler(listener, errorCode, message);
            }
        });
    }

    /**
     * 绑卡确认
     *
     * @param bind_card_id
     * @param order_no
     * @param check_rest
     * @param sms_code
     * @param base64Img
     * @param listener
     */
    @Override
    public void confirmBindCard(String bind_card_id, String order_no, String check_rest, String sms_code, String base64Img, ActionCallbackListener<Void> listener) {
        api.confirmBindCard(bind_card_id, order_no, check_rest, sms_code, base64Img, new ApiCallBack<ApiResponse<Void>>() {
            @Override
            public void onSuccess(ApiResponse<Void> data) {
                successNullHandler(listener);
            }

            @Override
            public void onFailure(String errorCode, String message) {
                failedHandler(listener, errorCode, message);
            }
        });
    }

    @Override
    public void getTransfeRecord(String transferType, int page, ActionCallbackListener<List<TransfeRecordBean>> listener) {
        api.getTransfeRecord(transferType, page, new ApiCallBack<ApiResponse<List<TransfeRecordBean>>>() {
            @Override
            public void onSuccess(ApiResponse<List<TransfeRecordBean>> data) {
                successHandler(data, listener);
            }

            @Override
            public void onFailure(String errorCode, String message) {
                failedHandler(listener, errorCode, message);
            }
        });
    }

    @Override
    public void getIntegralLog(String integral_type, String month, int page, ActionCallbackListener<List<IntegralRecordBean>> listener) {
        api.getIntegralLog(integral_type, month, page, new ApiCallBack<ApiResponse<List<IntegralRecordBean>>>() {
            @Override
            public void onSuccess(ApiResponse<List<IntegralRecordBean>> data) {
                successHandler(data, listener);
            }

            @Override
            public void onFailure(String errorCode, String message) {
                failedHandler(listener, errorCode, message);
            }
        });
    }

    @Override
    public void getMsgList(int page, ActionCallbackListener<List<UserMessageBean>> listener) {
        api.getMsgList(page, new ApiCallBack<ApiResponse<List<UserMessageBean>>>() {
            @Override
            public void onSuccess(ApiResponse<List<UserMessageBean>> data) {
                successHandler(data, listener);
            }

            @Override
            public void onFailure(String errorCode, String message) {
                failedHandler(listener, errorCode, message);
            }
        });
    }

    @Override
    public void getExperienceLog(int page, ActionCallbackListener<List<EXPRecordBean>> listener) {
        api.getExperienceLog(page, new ApiCallBack<ApiResponse<List<EXPRecordBean>>>() {
            @Override
            public void onSuccess(ApiResponse<List<EXPRecordBean>> data) {
                successHandler(data, listener);
            }

            @Override
            public void onFailure(String errorCode, String message) {
                failedHandler(listener, errorCode, message);
            }
        });
    }

    @Override
    public void getUserTicketList(String type, int page, ActionCallbackListener<List<TicketBean>> listener) {
        api.getUserTicketList(type, page, new ApiCallBack<ApiResponse<List<TicketBean>>>() {
            @Override
            public void onSuccess(ApiResponse<List<TicketBean>> data) {
                successHandler(data, listener);
            }

            @Override
            public void onFailure(String errorCode, String message) {
                failedHandler(listener, errorCode, message);
            }
        });
    }

    @Override
    public void getAvatarList(ActionCallbackListener<List<HeaderSelectBean>> listener) {
        api.getAvatarList(new ApiCallBack<ApiResponse<List<HeaderSelectBean>>>() {
            @Override
            public void onSuccess(ApiResponse<List<HeaderSelectBean>> data) {
                successHandler(data, listener);
            }

            @Override
            public void onFailure(String errorCode, String message) {
                failedHandler(listener, errorCode, message);

            }
        });
    }

    @Override
    public void editUserAvatar(String header_id, ActionCallbackListener<Void> listener) {
        api.editUserAvatar(header_id, new ApiCallBack<ApiResponse<Void>>() {
            @Override
            public void onSuccess(ApiResponse<Void> data) {
                successNullHandler(listener);
            }

            @Override
            public void onFailure(String errorCode, String message) {
                failedHandler(listener, errorCode, message);
            }
        });
    }

    @Override
    public void editUserNickName(String nickName, ActionCallbackListener<Void> listener) {
        api.editUserNickName(nickName, new ApiCallBack<ApiResponse<Void>>() {
            @Override
            public void onSuccess(ApiResponse<Void> data) {
                successNullHandler(listener);
            }

            @Override
            public void onFailure(String errorCode, String message) {
                failedHandler(listener, errorCode, message);
            }
        });
    }

    @Override
    public void getRetailOrderList(String status, String orderType, int page, ActionCallbackListener<List<RetailOrderBean>> listener) {
        api.getRetailOrderList(status, orderType, page, new ApiCallBack<ApiResponse<List<RetailOrderBean>>>() {
            @Override
            public void onSuccess(ApiResponse<List<RetailOrderBean>> data) {
                successHandler(data, listener);
            }

            @Override
            public void onFailure(String errorCode, String message) {
                failedHandler(listener, errorCode, message);
            }
        });
    }

    @Override
    public void confirmOrder(String order_id, ActionCallbackListener<Void> listener) {
        api.confirmOrder(order_id, new ApiCallBack<ApiResponse<Void>>() {
            @Override
            public void onSuccess(ApiResponse<Void> data) {
                successNullHandler(listener);
            }

            @Override
            public void onFailure(String errorCode, String message) {
                failedHandler(listener, errorCode, message);
            }
        });
    }

    @Override
    public void getMyFollowOrder(int page, String userId, ActionCallbackListener<List<FollowOrderBean>> listener) {
        api.getMyFollowOrder(page, userId, new ApiCallBack<ApiResponse<List<FollowOrderBean>>>() {
            @Override
            public void onSuccess(ApiResponse<List<FollowOrderBean>> data) {
                successHandler(data, listener);
            }

            @Override
            public void onFailure(String errorCode, String message) {
                failedHandler(listener, errorCode, message);
            }
        });
    }

    @Override
    public void followUser(FollowUserBean bean, ActionCallbackListener<Void> listener) {
        api.followUser(bean, new ApiCallBack<ApiResponse<Void>>() {
            @Override
            public void onSuccess(ApiResponse<Void> data) {
                successNullHandler(listener);
            }

            @Override
            public void onFailure(String errorCode, String message) {
                failedHandler(listener, errorCode, message);
            }
        });
    }

    @Override
    public void followList(int type, int page, ActionCallbackListener<List<FollowListBean>> listener) {
        api.followList(type, page, new ApiCallBack<ApiResponse<List<FollowListBean>>>() {
            @Override
            public void onSuccess(ApiResponse<List<FollowListBean>> data) {
                successHandler(data, listener);
            }

            @Override
            public void onFailure(String errorCode, String message) {
                failedHandler(listener, errorCode, message);
            }
        });
    }

    public void getRetailTicketList(ActionCallbackListener<List<RetailTicketBean>> listener) {
        api.getRetailTicketList(new ApiCallBack<ApiResponse<List<RetailTicketBean>>>() {
            @Override
            public void onSuccess(ApiResponse<List<RetailTicketBean>> data) {
                successHandler(data, listener);
            }

            @Override
            public void onFailure(String errorCode, String message) {
                failedHandler(listener, errorCode, message);
            }
        });
    }

    @Override
    public void editPushMsg(String msgIds, ActionCallbackListener<Void> listener) {
        api.editPushMsg(msgIds, new ApiCallBack<ApiResponse<Void>>() {
            @Override
            public void onSuccess(ApiResponse<Void> data) {
                successNullHandler(listener);
            }

            @Override
            public void onFailure(String errorCode, String message) {
                failedHandler(listener, errorCode, message);
            }
        });
    }

    @Override
    public void loopPushList(ActionCallbackListener<FreshListBean> listener) {
        api.loopPushList(new ApiCallBack<ApiResponse<FreshListBean>>() {
            @Override
            public void onSuccess(ApiResponse<FreshListBean> data) {
                successHandler(data, listener);
            }

            @Override
            public void onFailure(String errorCode, String message) {
                failedHandler(listener, errorCode, message);
            }
        });
    }

    @Override
    public void uploadPushId(String id, ActionCallbackListener<Void> listener) {
        api.uploadPushId(id, new ApiCallBack<ApiResponse<Void>>() {
            @Override
            public void onSuccess(ApiResponse<Void> data) {
                successNullHandler(listener);
            }

            @Override
            public void onFailure(String errorCode, String message) {
                failedHandler(listener, errorCode, message);
            }
        });
    }

    @Override
    public void updateVersion(String type, ActionCallbackListener<VersionBean> listener) {
        api.updateVersion(type, new ApiCallBack<ApiResponse<VersionBean>>() {
            @Override
            public void onSuccess(ApiResponse<VersionBean> data) {
                successHandler(data, listener);
            }

            @Override
            public void onFailure(String errorCode, String message) {
                failedHandler(listener, errorCode, message);
            }
        });
    }

    @Override
    public void getFollowGreatPeopleInfo(String userId, ActionCallbackListener<FollowGreatPeopleInfo> listener) {
        api.getFollowGreatPeopleInfo(userId, new ApiCallBack<ApiResponse<FollowGreatPeopleInfo>>() {
            @Override
            public void onSuccess(ApiResponse<FollowGreatPeopleInfo> data) {
                successHandler(data, listener);
            }

            @Override
            public void onFailure(String errorCode, String message) {
                failedHandler(listener, errorCode, message);
            }
        });
    }

    @Override
    public void getCalendarDetail(String id, final ActionCallbackListener<CalendarDetail> listener) {
        api.getCalendarDetail(id, new ApiCallBack<CalendarDetail>() {
            @Override
            public void onSuccess(final CalendarDetail data) {
                mHandler.post(new Runnable() {
                    @Override
                    public void run() {
                        listener.onSuccess(data);
                    }
                });
            }

            @Override
            public void onFailure(String errorCode, String message) {
                failedHandler(listener, errorCode, message);
            }
        });
    }

    @Override
    public void getImportNoticeDialog(ActionCallbackListener<ImportDialogBean> listener) {
        api.getImportNoticeDialog(new ApiCallBack<ApiResponse<ImportDialogBean>>() {
            @Override
            public void onSuccess(ApiResponse<ImportDialogBean> data) {
                successHandler(data, listener);
            }

            @Override
            public void onFailure(String errorCode, String message) {
                failedHandler(listener, errorCode, message);
            }
        });
    }

    @Override
    public void readNotice(String id, ActionCallbackListener<Void> listener) {
        api.readNotice(id, new ApiCallBack<ApiResponse<Void>>() {
            @Override
            public void onSuccess(ApiResponse<Void> data) {
                successNullHandler(listener);
            }

            @Override
            public void onFailure(String errorCode, String message) {
                failedHandler(listener, errorCode, message);
            }
        });
    }

    @Override
    public void getRedBagList(ActionCallbackListener<List<RedBagBean>> listener) {
        api.getRedBagList(new ApiCallBack<ApiResponse<List<RedBagBean>>>() {
            @Override
            public void onSuccess(ApiResponse<List<RedBagBean>> data) {
                successHandler(data, listener);
            }

            @Override
            public void onFailure(String errorCode, String message) {
                failedHandler(listener, errorCode, message);
            }
        });
    }

    @Override
    public void drawRedBag(ActionCallbackListener<Void> listener) {
        api.drawRedBag(new ApiCallBack<ApiResponse<Void>>() {
            @Override
            public void onSuccess(ApiResponse<Void> data) {
                successNullHandler(listener);
            }

            @Override
            public void onFailure(String errorCode, String message) {
                failedHandler(listener, errorCode, message);
            }
        });
    }

    @Override
    public void getTurnCardList(ActionCallbackListener<TurnCardBean> listener) {
        api.getTurnCardList(new ApiCallBack<ApiResponse<TurnCardBean>>() {
            @Override
            public void onSuccess(ApiResponse<TurnCardBean> data) {
                successHandler(data, listener);
            }

            @Override
            public void onFailure(String errorCode, String message) {
                failedHandler(listener, errorCode, message);
            }
        });
    }

    @Override
    public void drawTurnCard(ActionCallbackListener<TurnCardBean> listener) {
        api.drawTurnCard(new ApiCallBack<ApiResponse<TurnCardBean>>() {
            @Override
            public void onSuccess(ApiResponse<TurnCardBean> data) {
                successHandler(data, listener);
            }

            @Override
            public void onFailure(String errorCode, String message) {
                failedHandler(listener, errorCode, message);
            }
        });
    }

    @Override
    public void adPost(ActionCallbackListener<Void> listener) {
        LogUtil.e("dangzt", "推广上报到请求");
        api.adPost(new ApiCallBack<ApiResponse<Void>>() {
            @Override
            public void onSuccess(ApiResponse<Void> data) {
                successNullHandler(listener);
            }

            @Override
            public void onFailure(String errorCode, String message) {
                failedHandler(listener, errorCode, message);
            }
        });
    }

    @Override
    public void getCalendarData(String date, final ActionCallbackListener<List<CalendarBean>> listener) {
        api.getCalendarData(date, new ApiCallBack<List<CalendarBean>>() {
            @Override
            public void onSuccess(final List<CalendarBean> data) {
                mHandler.post(new Runnable() {
                    @Override
                    public void run() {
                        listener.onSuccess(data);
                    }
                });
            }

            @Override
            public void onFailure(String errorCode, String message) {
                failedHandler(listener, errorCode, message);
            }
        });
    }

    public void getHomeData(String type, ActionCallbackListener<HomeData> listener) {
        api.getHomeData(type, new ApiCallBack<ApiResponse<HomeData>>() {
            @Override
            public void onSuccess(ApiResponse<HomeData> data) {
                successHandler(data, listener);
            }

            @Override
            public void onFailure(String errorCode, String message) {
                failedHandler(listener, errorCode, message);
            }
        });
    }

    @Override
    public void getUserBalance(ActionCallbackListener<UserBalanceBean> listener) {
        api.getUserBalance(new ApiCallBack<ApiResponse<UserBalanceBean>>() {
            @Override
            public void onSuccess(ApiResponse<UserBalanceBean> data) {
                successHandler(data, listener);
            }

            @Override
            public void onFailure(String errorCode, String message) {
                failedHandler(listener, errorCode, message);
            }
        });
    }

    @Override
    public void getPayPasswordCode(ActionCallbackListener<Void> listener) {
        api.getPayPasswordCode(new ApiCallBack<ApiResponse<Void>>() {
            @Override
            public void onSuccess(ApiResponse<Void> data) {
                successNullHandler(listener);
            }

            @Override
            public void onFailure(String errorCode, String message) {
                failedHandler(listener, errorCode, message);
            }
        });
    }

    @Override
    public void setPayPassword(String code, String password, String confirmPasswrod, ActionCallbackListener<Void> listener) {
        if (code == null || code.isEmpty()) {
            failedHandler(listener, Constant.FAILED, "请输入验证码");
        } else if (password == null || password.isEmpty()) {
            failedHandler(listener, Constant.FAILED, "请输入新密码");
        } else if (confirmPasswrod == null || confirmPasswrod.isEmpty()) {
            failedHandler(listener, Constant.FAILED, "请输入确认密码");
        } else {
            api.setPayPassword(code, password, confirmPasswrod, new ApiCallBack<ApiResponse<Void>>() {
                @Override
                public void onSuccess(ApiResponse<Void> data) {
                    successNullHandler(listener);
                }

                @Override
                public void onFailure(String errorCode, String message) {
                    failedHandler(listener, errorCode, message);
                }
            });
        }
    }

    private void successNullHandler(final ActionCallbackListener listener) {
        mHandler.post(() -> listener.onSuccess(null));
    }

    private void successHandler(final ApiResponse data, final ActionCallbackListener listener) {
        if (data != null && data.getData() != null) {
            mHandler.post(() -> listener.onSuccess(data.getData()));
        } else {
            failedHandler(listener, Constant.FAILED, Constant.NULL_DATA_MSG);
        }
    }

    private void failedHandler(final ActionCallbackListener listener, final String errorCode, final String message) {
        mHandler.post(() -> listener.onFailure(errorCode, message));
    }
}
